﻿#region Usings

using System;
using System.Collections.Generic;
using Rail.Net.Common;

#endregion

namespace Rail.Net.Core.Model.Nonpersistent
{
    public enum DomesticTarifType
    {
        FullPrice,
        Vorteilscard,
        VorteilscardFamily,
        Businesscard,
        BusinesscardBonus,
        Minimax,
        MinimaxVc
    }

    public class PriceShareCalculator
    {
        public static void SetDomesticPriceShare(SearchModel searchModel, DomesticTarifType tarifType,
                                                 List<List<decimal>> shares1, List<List<decimal>> shares2, int seqIndex)
        {
            var numberOfNoAdults = searchModel.NumberOfAdults*2;
            for (var i = 0; i < searchModel.Travelers.Count; i++)
            {
                var age = Int32.Parse(searchModel.Travelers[i].Age.SelectedItem.Value);
                var share = (age >= 15 ? 1 : (age < 6 ? 0 : 0.5m));

                switch (tarifType)
                {
                    case DomesticTarifType.Vorteilscard:
                        {
                            if (searchModel.Travelers[i].Discount.SelectedItem.Value == Constants.VorteilsCard ||
                                searchModel.Travelers[i].Discount.SelectedItem.Name == Constants.VorteilsCard26)
                            {
                                share *= 0.5m;
                            }
                            break;
                        }
                    case DomesticTarifType.VorteilscardFamily:
                        {
                            if (age >= 15)
                            {
                                share *= 0.5m;
                            }
                            else if (age < 15 && age >= 6 && numberOfNoAdults > 0)
                            {
                                share *= 0m;

                                numberOfNoAdults--;
                            }
                            break;
                        }
                    case DomesticTarifType.Minimax:
                        {
                            share *= (1 - (i + 1)*0.1m);

                            break;
                        }
                    case DomesticTarifType.MinimaxVc:
                        {
                            share *= (1 - (i*0.1m + 0.5m));

                            break;
                        }
                    case DomesticTarifType.Businesscard:
                        {
                            share *= 0.8m;

                            break;
                        }
                    case DomesticTarifType.BusinesscardBonus:
                        {
                            share *= 0.76m;

                            break;
                        }
                    default:
                        {
                            break;
                        }
                }

                shares1[seqIndex][i] = share;
                shares2[seqIndex][i] = share;
            }
        }
    }
}